package com.wa.vo;

import com.wa.constants.BomWebSocketPackageTypeConstant;
import com.wa.util.UUIDGenerator;

import java.util.Date;

/**
 * bom系统websocket请求
 *
 * @author recharde.li
 * @create 2019-09-02
 */
public class BomWebSocketPackage<T>{

    /**
     * 包类型
     * see also {@linkplain BomWebSocketPackageTypeConstant}
     */
    private Integer type;

    /**
     * 包类型
     * see also {@linkplain BomWebSocketPackageTypeConstant}
     */
    private String typeCN;

    /**
     * 请求体、响应体
     */
    private T body;

    /**
     * 请求时间
     */
    private Date time;

    /**
     * 序列号
     */
    private String number;

    /**
     * 额外信息，如页面信息displayModule、、、
     */
    private Object extra;

    public BomWebSocketPackage() {
        this.time = new Date();
        this.number = UUIDGenerator.generate();
        this.type = BomWebSocketPackageTypeConstant.WEB_SOCKET_PING_MESSAGE;
        this.typeCN = BomWebSocketPackageTypeConstant.getBomWebSocketPackageTypeConstantMap().get(this.type);
    }

    public BomWebSocketPackage(Integer type) {
        this.type = type;
        this.time = new Date();
        this.number = UUIDGenerator.generate();
        this.typeCN = BomWebSocketPackageTypeConstant.getBomWebSocketPackageTypeConstantMap().get(this.type);
    }

    public BomWebSocketPackage(Integer type, T body) {
        this.type = type;
        this.body = body;
        this.time = new Date();
        this.number = UUIDGenerator.generate();
        this.typeCN = BomWebSocketPackageTypeConstant.getBomWebSocketPackageTypeConstantMap().get(this.type);
    }

    public Integer getType() {
        return type;
    }

    public BomWebSocketPackage<T> setType(Integer type) {
        this.type = type;
        this.typeCN = BomWebSocketPackageTypeConstant.getBomWebSocketPackageTypeConstantMap().get(this.type);
        return this;
    }

    public String getTypeCN() {
        return BomWebSocketPackageTypeConstant.getBomWebSocketPackageTypeConstantMap().get(this.type);
    }

    public BomWebSocketPackage<T> setTypeCN(String typeCN) {
        this.typeCN = typeCN;
        return this;
    }

    public T getBody() {
        return body;
    }

    public BomWebSocketPackage<T> setBody(T body) {
        this.body = body;
        return this;
    }

    public Date getTime() {
        return time;
    }

    public BomWebSocketPackage<T> setTime(Date time) {
        this.time = time;
        return this;
    }

    public String getNumber() {
        return number;
    }

    public BomWebSocketPackage<T> setNumber(String number) {
        this.number = number;
        return this;
    }

    public Object getExtra() {
        return extra;
    }

    public BomWebSocketPackage<T> setExtra(Object extra) {
        this.extra = extra;
        return this;
    }
}
